package com.onion.auth.support.vo;

import java.util.*;

/**
 * 默认用户授权信息
 */
public class DefaultAuthorizationInfo implements AuthorizationInfo{

    private Set<String> roles = new HashSet<>();
    private Map<String, Collection<String>> permissions = new HashMap<>();

    @Override
    public Collection<String> getRoles() {
        return roles;
    }
    public void setRoles(Set<String> userRoles) {
        this.roles = userRoles;
    }
    public void addRole(String userRole){
        this.roles.add(userRole);
    }
    public void addAllRoles(Collection<String> userRoles){
        this.roles.addAll(userRoles);
    }

    @Override
    public Collection<String> getPermissions(String type) {
        return permissions.get(type);
    }
    @Override
    public Collection<String> getAllPermissions() {
        List<String> permissionList = new LinkedList<>();
        for(Collection<String> permissionSet : permissions.values()){
            permissionList.addAll(permissionSet);
        }
        return permissionList;
    }
    public void setPermissions(String type, Set<String> permissions){
        this.permissions.put(type, permissions);
    }

    @Override
    public Map<String, Collection<String>> getPermissions() {
        return this.permissions;
    }
    public void setPermissions(Map<String, Collection<String>> permissions){
        this.permissions = permissions;
    }


    public Collection<String> getExactPermissions() {
        return this.getPermissions("exact");
    }
    public void setExactPermissions(Set<String> permissions) {
        this.setPermissions("exact", permissions);
    }

    public Collection<String> getVaguePermissions() {
        return this.getPermissions("vague");
    }
    public void setVaguePermissions(Set<String> permissions){
        this.setPermissions("vague", permissions);
    }

}